#include <stdio.h>
#include "table.h"
#include "cstring.h"

#define TEST_BEFORE_COMPLIATION

#ifdef TEST_BEFORE_COMPLIATION
#include "cstring.c"
#include "table.c"
#endif



int test_table() {
	char k1[] = "admin";
	char k2[] = "aaaa";
	char k3[] = "qmd223";
	char v1[] = "root";
	char v2[] = "12345";
	char v3[] = "5dfh43";
	
	table tb = {};
	tb_set(tb, k1, v1);
	tb_set(tb, k2, v2);
	tb_set(tb, k3, v3);
	
	for (kvp* in_pairs(tb, kv))
		printf("%s: %s\n", kv->key, kv->val);
	
	printf("一共有%d个键\n", tb_len(tb));
	
	int k2_idx = tb_find(tb, k2);
	tb_del(tb, k2);
	
	printf("现在还剩%d个键↓\n", tb_len(tb));
	
	for (kvp* in_pairs(tb, kv))
		printf("%s: %s\n", kv->key, kv->val);
	
	tb_set(tb, k2, "0000");
	tb_set(tb, k2, "1111");
	
	printf("现在有%d个键\n", tb_len(tb));
	
	for (kvp* in_pairs(tb, kv))
		printf("%s: %s\n", kv->key, kv->val);
	
	int k2_idx_new = tb_find(tb, k2);
	if (k2_idx == k2_idx_new)
		printf("复用了已解绑的槽: %d\n", k2_idx);
	
	table tb_1 = {};
	if (!next(tb_1))
		printf("这是一个空table\n");
	
	printf("一共有%d个键\n", tb_len(tb_1));
	return 0;
}

int test_cstring() {
	string a = s("hello world");
	String.print(a);
	
	printf("长度 %llu\n", a->length);
	
	string b = String.reverse(a);
	String.print(b);
	
	string c = String.sub(a, 0, 6);
	String.print(c);
	
	string d = s("hello world");
	if (a == d)
		String.print(s("是同一个对象"));
	
	printf("查看地址：\n%p\n%p\n", a, d);
	
	string e = s("orld");
	string f = String.concat(c, e);
	if (a == f)
		String.print(f);
	
	double pi = 3.14159265358979323;
	String.print(tostring(pi));

	string symb = s('#');
	String.print(String.rep(symb, 10));
	
	int year = tonumber(String.input("输入年份："));
	int mouth = tonumber(String.input("输入月份："));
	int day = tonumber(String.input("输入日期："));
	
	string g = String.format("输入的日期是 %d年%d月%d日", year, mouth, day);
	String.print(g);
	
	String.freeall();
	return 0;
}



int main() {
    test_table();
    putchar('\n');
	test_cstring();
	return 0;
}